<template>
    <div class="home" ref="homeRef">
        <el-row :gutter="24" justify="center" style="margin-left: 0;margin-right: 0;">
            <div class="main-header">
                <span>{{header_msg}}</span>
            </div>

            <el-col :md="20" :sm="24" :xs="24">
                <ChatCard :query="c['query']" :answer="c['answer']" :model_name="c['model_name']" :responseTime="c['responseTime']" :finishTime="c['finishTime']" v-for="c in chat"/>
                
                <div class="welcome-container" v-if="chat.length === 0">
                    <div class="welcome-header">
                        <h1 class="welcome-title">矿小言 · 智能对话平台</h1>
                        <p class="welcome-subtitle">基于AI技术的多功能对话系统，为您提供专业、高效的智能服务</p>
                    </div>
                    
                    <el-row :gutter="20" class="feature-section">
                        <el-col :md="12" :sm="24" :xs="24">
                            <div class="feature-card local-feature">
                                <div class="feature-icon">
                                    <i class="el-icon-cpu"></i>
                                </div>
                                <h2>本地智能引擎</h2>
                                <p class="feature-desc">基于Python构建的本地AI处理能力</p>
                                
                                <div class="feature-list">
                                    <div class="feature-item">
                                        <div class="item-header">
                                            <span class="item-number">1</span>
                                            <span class="item-title">智能对话</span>
                                        </div>
                                        <p class="item-desc">支持ChatGLM3-6b等多种开源模型</p>
                                    </div>
                                    
                                    <div class="feature-item">
                                        <div class="item-header">
                                            <span class="item-number">2</span>
                                            <span class="item-title">知识库系统</span>
                                        </div>
                                        <p class="item-desc">支持PDF/Word等文档解析</p>
                                    </div>
                                    
                                    <div class="feature-item">
                                        <div class="item-header">
                                            <span class="item-number">3</span>
                                            <span class="item-title">联网搜索</span>
                                        </div>
                                        <p class="item-desc">实时获取最新网络信息</p>
                                    </div>
                                </div>
                            </div>
                        </el-col>
                        
                        <el-col :md="12" :sm="24" :xs="24">
                            <div class="feature-card cloud-feature">
                                <div class="feature-icon">
                                    <i class="el-icon-cloudy"></i>
                                </div>
                                <h2>云端模型支持</h2>
                                <p class="feature-desc">通过API接入各大AI平台优质模型</p>
                                
                                <div class="feature-list">
                                    <div class="feature-item">
                                        <div class="item-header">
                                            <span class="item-number">1</span>
                                            <span class="item-title">阿里云平台</span>
                                        </div>
                                        <p class="item-desc">多种大模型版本</p>
                                    </div>
                                    
                                    <div class="feature-item">
                                        <div class="item-header">
                                            <span class="item-number">2</span>
                                            <span class="item-title">讯飞星火</span>
                                        </div>
                                        <p class="item-desc">专业中文处理能力</p>
                                    </div>
                                    
                                    <div class="feature-item">
                                        <div class="item-header">
                                            <span class="item-number">3</span>
                                            <span class="item-title">智谱AI</span>
                                        </div>
                                        <p class="item-desc">高效的知识推理能力</p>
                                    </div>
                                </div>
                            </div>
                        </el-col>
                    </el-row>
                    
                    <div class="action-section">
                        <el-button type="primary" round @click="$router.push('/setting')" class="start-btn">
                            <i class="el-icon-setting"></i> 开始配置
                        </el-button>
                        <div class="doc-links">
                            <el-link type="primary" href="https://github.com/666xz666/ChatCUMT-UI" target="_blank">
                                <i class="el-icon-star-off"></i> GitHub源码
                            </el-link>
                            <el-link type="primary" @click="goTo('/tutorial')">
                                <i class="el-icon-document"></i> 使用文档
                            </el-link>
                        </div>
                    </div>
                </div>
            </el-col>
        </el-row>
    </div>
</template>

<script>
export default {
    name: 'AppMain',
    computed: {
        active() {
            return this.$store.state.app.active;
        },
        chat() {
            let chats = this.$store.state.app.chats;
            try {
                return chats.filter(item => item.uuid === this.active)[0]['data'];
            } catch (error) {
                return []
            }
        },
        header_msg() {
            if (this.$store.state.setting.method === 'local') {
                return 'ChatCUMT调用'+ ' ' + (this.$store.state.setting.memory ? '多轮对话' : '单轮对话');
            } else {
                return '远程调用' + ' ' + this.$store.state.setting.model_version + ' ' + (this.$store.state.setting.memory ? '多轮对话' : '单轮对话');
            }
        }
    },
    watch: {
        "$store.state.app.chats":{
            deep:true,
            handler:function(newVal,oldVal){
                let isAtBottom = this.$refs.homeRef.scrollTop + this.$refs.homeRef.clientHeight >= this.$refs.homeRef.scrollHeight - 100;
                if (!isAtBottom) return;
                this.$nextTick(() => {
                    this.$refs.homeRef.scrollTop = this.$refs.homeRef.scrollHeight
                });
            }
        },
        "$store.state.app.active":{
            deep:true,
            handler:function(newVal,oldVal){
                this.$nextTick(() => {
                    this.$refs.homeRef.scrollTop = this.$refs.homeRef.scrollHeight
                });
            }
        },
        query: function (newVal, oldVal) {
            this.$nextTick(() => {
                this.$refs.homeRef.scrollTop = this.$refs.homeRef.scrollHeight
            });
        }
    },
    created() {
        this.$nextTick(() => {
            this.$refs.homeRef.scrollTop = this.$refs.homeRef.scrollHeight
        });
    },
    methods: {
        goTo(path) {
            this.$router.push(path)
        },
    }
}
</script>

<style sc>
.main-header {
    position: fixed;
    margin-top: -18px;
    font-size: 12px;
    color: var(--chat-card-font-color);
}

.home {
    height: 100%;
    overflow-y: auto;
    scrollbar-width: none;
}

.home::-webkit-scrollbar {
    display: none;
}

.welcome-container {
    transform: scale(0.9); /* 根据页面大小可调，如 0.8~0.95 */
    transform-origin: top center;
    max-width: 900px;
    margin: 10px auto;
    padding: 10px 20px 20px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

.welcome-header {
    text-align: center;
    margin-bottom: 20px;
}

.welcome-title {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #2454ff 0%, #00b4ff 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.welcome-subtitle {
    font-size: 0.95rem;
    color: #666;
    margin: 0 auto;
    max-width: 500px;
}

.feature-section {
    margin: 10px 0 30px;
    display: flex;
    flex-wrap: wrap;
}

.feature-card {
    padding: 20px;
    border-radius: 10px;
    height: 340px;
    transition: all 0.3s ease;
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
}

.local-feature {
    background: linear-gradient(135deg, #eaf3ff 0%, #dceeff 100%);
    border: 1px solid #c2dcff;
    box-shadow: 0 4px 14px rgba(36, 84, 255, 0.08);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.cloud-feature {
    background: linear-gradient(135deg, #e6f1ff 0%, #d3e9ff 100%);
    border: 1px solid #bcd9ff;
    box-shadow: 0 4px 14px rgba(36, 84, 255, 0.08);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.feature-icon {
    font-size: 2rem;
    color: #3b82f6; /* 明亮蓝色 */
    margin-bottom: 12px;
}
.feature-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(36, 84, 255, 0.15);
}


/* 数字圆圈样式 */
.item-number {
    background: #3b82f6;
}
.feature-card h2 {
    font-size: 1.3rem;
    margin-bottom: 8px;
    color: #1a2029;
    margin-top: -10px;
}

.feature-desc {
    color: #444;
    margin-bottom: 15px;
    font-size: 0.9rem;
}

.feature-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    flex-grow: 1;
}

.feature-item {
    display: flex;
    flex-direction: column;
}

.item-header {
    display: flex;
    align-items: center;
    margin-bottom: 3px;
}

.item-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    background: #2454ff;
    color: white;
    border-radius: 50%;
    font-size: 0.7rem;
    margin-right: 8px;
}

.item-title {
    font-weight: 600;
    color: #1a2029;
    font-size: 0.95rem;
}

.item-desc {
    color: #444;
    font-size: 0.85rem;
    margin-left: 30px;
    line-height: 1.4;
}

.action-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 30px;
    padding-top: 20px;
}

.start-btn {
    padding: 10px 24px;
    font-size: 0.95rem;
    font-weight: 500;
}

.doc-links {
    margin-top: 15px;
    display: flex;
    gap: 15px;
}

.el-link {
    font-size: 0.9rem;
}

@media (max-width: 768px) {
    .welcome-container {
        padding: 15px;
    }
    
    .welcome-title {
        font-size: 1.5rem;
    }
    
    .welcome-subtitle {
        font-size: 0.9rem;
    }
    
    .feature-card {
        height: auto;
        min-height: 280px;
        margin-bottom: 20px;
    }
    
    .action-section {
        margin-top: 20px;
    }
}
</style>